<%@ page language="java"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <title>工序模板</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>js/bootstrap-3.3.6/dist/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrapValidator.css"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/mydialog.css"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css"/>
    <script type="text/javascript" src="<%=basePath%>js/common/jquery-2.1.0.js" charset="utf-8"></script>

    <script type="text/javascript" src="<%=basePath%>js/common/dialog.3.1.min.js"></script>

<body>
<div id="index-hav2">
    <div class="index-hav-right" id="index-hav-right-clear">
        <div class="row">
            <div class="col-md-9">
                <span id="icon-house"> </span><span>首页</span>
                <span>></span><span>系统管理</span>
                <span>></span><span>工序模板</span>
            </div>
            <div class="bank-box">
                <div class="lianlian platform">
                    <!-- 搜索 -->
                    <div class="col-md-12">
                        <form role="form" id="queryForm" method="post">
                            <table class="textTable">
                                <tr>
                                    <td class="platform-start"> </td>
                                    <th class="">
                                        <%--<input type="text" class="form-control" name="code"--%>
                                               <%--value="${map['code'] }"/>--%>
                                    </th>
                                </tr>
                            </table>
                            <ul class="textBtn">
                                <li class="">
                                    <%--<button class="search-form-btn-s btn btn-primary btn-sm">查询</button>--%>
                                    <%--<a type="button" class="clearForm btn btn-primary btn-sm">重置</a>--%>
                                    <a type="button" class="btn btn-primary btn-sm"
                                       href="<%=path%>/system/workingProcedureTemplate/templateById">新增模板
                                    </a>
                                </li>
                            </ul>
                        </form>

                        <table class="control-tatle table table-striped table-bordered table-hover"
                               action="<%=path%>/system/workingProcedureTemplate/template/list">
                            <thead class="financing-thead">
                            <tr>
                                <th style="width: 4%">序号</th>
                                <th style="width: 5%">创建人</th>
                                <th style="width: 6%">创建时间</th>
                                <th style="width: 6%">难易度</th>
                                <th style="width: 6%">次型</th>
                                <th style="width: 12%">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${not empty templateList}">
                                <c:forEach items="${templateList }" var="model" varStatus="r">
                                    <tr>
                                        <td>${r.index+1 }</td>
                                        <td>${model.insertedBy }</td>
                                        <td><fmt:formatDate value="${model.insertedAt }" pattern="yyyy-MM-dd"/></td>
                                        <td>${model.level }</td>
                                        <td>${model.type }次型</td>
                                        <td id="${model.id }">
                                            <a class="hand-like"
                                               href="<%=path%>/system/workingProcedureTemplate/templateById?code=${model.code }">修改
                                            </a>
                                            <%--<a style="cursor:pointer;" class="hand-like" onclick="del(${model.code })">删除</a>--%>
                                        </td>
                                        <input type="hidden" class="hiddenId" id="id" value="">
                                    </tr>
                                </c:forEach>
                            </c:if>
                            <c:if test="${empty templateList}">
                                <tr>
                                    <td colspan="15"><label class="control-label text-center">无记录</label>
                                        <div class="alert alert-warning" role="alert">
                                            <a class="btn btn-sm btn-success"
                                               href="<%=path%>/system/workingProcedureTemplate/templateById">
                                                新增模板
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                            </c:if>
                            </tbody>
                            <tr style="background:#f8f8f8">
                                <td colspan="12">
                                    <jsp:include page="/WEB-INF/jsp/page.jsp"></jsp:include>
                                </td>
                            </tr>
                        </table>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="gray-screen"></div>

</body>
<script type="text/javascript" src="<%=basePath%>js/validate/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/rem.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/bootstrapValidator.js"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/zh_CN.js"></script>
<script type="text/javascript" src="<%=basePath%>js/bootstrap-3.3.6/dist/js/bootstrap.min.js" charset="utf-8"></script>
<script>

    function del(code) {
        var flag = confirm("确定要删除版本号:" + code + " 下的所有记录?");
        if (flag) {
            $.ajax({
                type: "get",
                url: "<%=path%>/system/workingProcedureTemplate/deleteCode/templates?code=" + code,
                dataType: "json",
                success: function (data) {
                    if (data.message != undefined) {
                        Dialog({
                            "msg": '<div class="D_alert">' + data.message + '</div>',
                            "title": "提示",
                            "showButtons": true,
                            "cancelButton": false,
                            "onComplete": function () {
                                grayScreen.style.display = "none";
                                window.location.reload();
                            }
                        });
                    } else {
                        window.location.reload();
                    }
                }
            });
        } else {
            alert('已取消操作!');
        }
    }

</script>

<script type="text/javascript">
    $(document).ready(function () {
        //提交表单
        $(".queryForm").click(function () {
            var data = $("#queryForm").serialize();
            window.location.href = "<%=path%>/system/workingProcedureTemplate/template/list?" + data;
        });
        //清空搜索条件
        $(".clearForm").click(function () {
            $("#queryForm").find("input").val("");
            $("#queryForm").find("select").val("");
        });
        $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                parentId: {
                    validators: {
                        notEmpty: {}
                    }
                },
                linkMail: {
                    validators: {
                        notEmpty: {}
                    }
                },
            }
        }).on('success.form.bv', function (e) {
            // Prevent form submission
            e.preventDefault();
            // Get the form instance
            var $form = $(e.target)
            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');
            // Use Ajax to submit form data
            $.post($form.attr('action'), $form.serialize(), function (result) {
                var grayScreen = document.getElementById("gray-screen");
                Dialog({
                    "msg": '<div class="D_alert">' + result.message + '</div>',
                    "title": "提示",
                    "showButtons": true,
                    "cancelButton": false,
                    "onComplete": function () {
                        $("body").empty();
                        window.location.href = '<%=path%>/system/workingProcedureTemplate/template/list';
                    }
                });
            }, 'json');
        });
    });
</script>
</html>